# include <bits/stdc++.h>
# define mid ((l + r) >> 1)
using namespace std;

inline char getc() {
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline int gn() {
    register int k = 0, f = 1;
    register char c = getc();
    for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return k * f;
}

int sum_of_AP(int n, int d, int a1) {
    return (n * (a1 + (a1 + d * (n - 1))) >> 1);
}

struct node {
    int sum, a1, d, lz[2];
    node *ls, *rs;
    node() {
        ls = rs = NULL;
        sum = a1 = d = lz[0] = lz[1] = 0;
    }
    void pd(int l, int r) {
        if(lz[1]) {
            ls->sum += sum_of_AP(mid - l + 1, lz[1], lz[0]);
            rs->sum += sum_of_AP(r - mid, (mid - l + 1) *lz[1], lz[0]);
            ls->lz[0] = lz[0];
            ls->lz[1] = lz[1];
            rs->lz[1] = lz[1];
            rs->lz[0] = lz[0] + (mid - l + 1) * lz[1];
            lz[0] = lz[1] = 0;
        }
    }
    void pu(int l, int r) {
        sum = ls->sum + rs->sum;
    }
} *root;

node *build(int l, int r) {
    node *x = new node();
    if(l ^ r) {
        x->ls = build(l, mid);
        x->rs = build(mid + 1, r);
    }
    return x;
}
void change(node *x, int l, int r, int s, int t, int aa1, int dd) {
    x->pd(l, r);
    if(l == s && r == t) {
        x->pd(l, r);
        x->sum += sum_of_AP(r - l + 1, dd, aa1);
        x->lz[0] = aa1;
        x->lz[1] = dd;
        return;
    }
    else if(t <= mid) change(x->ls, l, mid, s, t, aa1, dd);
    else if(s > mid) change(x->rs, mid + 1, r, s, t, aa1, dd);
    else change(x->ls, l, mid, s, mid, aa1, dd),
         change(x->rs, mid + 1, r, mid + 1, t, aa1 + (mid - l + 1) * dd, dd);
    x->pd(l, r);
    x->pu(l, r);
}

int query(node *x, int l, int r, int s, int t) {
    x->pd(l, r);
    if(l == s && r == t) {
        return x->sum;
    }
    else if(t <= mid) return query(x->ls, l, mid, s, t);
    else if(s > mid) return query(x->rs, mid + 1, r, s, t);
    else return query(x->ls, l, mid, s, mid)
              + query(x->rs, mid + 1, r, mid + 1, t);
}

int n, m;

int main() {
# ifdef LOCAL
    freopen("in", "r", stdin);
# endif
    n = gn();
    m = gn();
    root = build(1, n);
    for(int i = 1; i <= m; i++) {
        int op = gn(), l = gn(), r = gn();
        if(op == 1) {
            change(root, 1, n, l, r, 0, gn());
        } else {
            printf("%d\n", query(root, 1, n, l, r));
        }
    }
}
